<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Increment Number</title>
    <style>
        /* 设置body为全屏高度，开启Flex布局，居中对齐 */
        body {
            height: 100vh;
            margin: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-direction: column;
            /* 垂直排列 */
            font-family: Arial, sans-serif;
            /* 设置字体 */
        }

        .footer {
            position: fixed;
            bottom: 0;
            width: 100%;
            text-align: center;
        }
    </style>
    <script>

        function focusObservr() {
            if (window.flutter_inappwebview) {
                window.flutter_inappwebview.callHandler('messageChannel', JSON.stringify({ type: 'keyboardForObserver', data: '1' })).then(function (result) {
                    // alert(result);
                });
            } else {
                window.flutter_inappwebview._callHandler('messageChannel', JSON.stringify({ type: 'keyboardForObserver', data: '1' })).then(function (result) {
                    // alert(result);
                });
            }
        }
        focusObservr();

        window.onKeyboardHeight = (data) => {
            console.log(data['height']);
            // alert(data);
        }

        window.onEmailUpdate = (data) => {
            console.log(data['code']);
            console.log(data['email']);
            console.log(data['msg']);
            // alert(data);
        }
        function increment() {
            var textBox = document.getElementById("numberBox");
            var currentNumber = parseInt(textBox.value, 10);
            textBox.value = currentNumber + 1;
        }

        function getEmail() {
            if (window.flutter_inappwebview) {
                console.log('window.flutter_inappwebview.callHandler');
                var textBox = document.getElementById("numberBox");
                textBox.value = '1'
                window.flutter_inappwebview.callHandler('messageChannel', JSON.stringify({ type: 'getUserEmail' })).then(function (result) {
                    // alert(result);
                });
            } else {
                var textBox = document.getElementById("numberBox");
                textBox.value = '2'

                console.log('window.flutter_inappwebview._callHandler');
                window.flutter_inappwebview._callHandler('messageChannel', null, JSON.stringify({ type: 'getUserEmail' })).then(function (result) {
                    // alert(result);
                });
            }
        }

        function keyboardUnfocus() {
            if (window.flutter_inappwebview) {
                window.flutter_inappwebview.callHandler('messageChannel', JSON.stringify({ type: 'keyboardUnfocus' })).then(function (result) {
                    // alert(result);
                });
            } else {
                window.flutter_inappwebview._callHandler('messageChannel', JSON.stringify({ type: 'keyboardUnfocus' })).then(function (result) {
                    // alert(result);
                });
            }
        }

        function showLoading() {
            var data = {
                'title': '加载中',
                'timeout': 10000,
            }
            if (window.flutter_inappwebview) {
                window.flutter_inappwebview.callHandler('messageChannel', JSON.stringify({
                    type: 'showLoading', data: data
                })).then(function (result) {
                    // alert(result);
                });
            } else {
                window.flutter_inappwebview._callHandler('messageChannel', JSON.stringify({ type: 'showLoading', data: data })).then(function (result) {
                    // alert(result);
                });
            }
            setTimeout(hideLoading, 3000);
        }
        function hideLoading() {
            if (window.flutter_inappwebview) {
                window.flutter_inappwebview.callHandler('messageChannel', JSON.stringify({
                    type: 'hideLoading'
                })).then(function (result) {
                    // alert(result);
                });
            } else {
                window.flutter_inappwebview._callHandler('messageChannel', JSON.stringify({ type: 'hideLoading' })).then(function (result) {
                    // alert(result);
                });
            }
        }
    </script>
</head>

<body>
    <input id="numberBox" type="text" value="0" readonly />
    <button onclick="getEmail()">点击获取邮箱2</button>
    <div class="footer">
        <input id="inputField" type="text" placeholder="请输入内容">
        <button onclick="keyboardUnfocus()">提交</button>
        <button onclick="showLoading()">弹出loading</button>
    </div>


</body>

</html>